package com.orhon.smartcampus.modules.base.entity;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.annotations.Where;

import com.orhon.smartcampus.modules.student.entity.SInformation;
import com.orhon.smartcampus.modules.systemctl.entity.Modules;
import com.orhon.smartcampus.modules.systemctl.entity.Schoolsettings;
import com.orhon.smartcampus.modules.teacher.entity.TInformation;
import com.orhon.smartcampus.modules.user.entity.Users;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;


@Setter
@Getter
@EqualsAndHashCode
@Entity
@Table(name = "base_schools")
public class Schools {

	@Id
	@Column(name = "id", nullable = false)
	@GeneratedValue
	private Long id;  //"学校 id"

	@Column(name = "school_slug")
	private String school_slug;  //"学校别名" 

	@Column(name = "school_number")
	private String school_number;  //"学校编号"  

	@Column(name = "school_order")
	private Integer school_order;  //"顺序"   

	@Column(name = "created_at")
	private Date created_at;

	@Column(name = "updated_at")
	private Date updated_at;

	@Column(name = "school_type")
	private String school_type;  //"学校类型"

	@Column(name = "region_id")
	private Integer region_id;  //"学校所属地区id"

	@Column(name = "school_client_key")
	private String school_client_key;  //"orhonedu对应学校客户key"   

	@Column(name = "client_secret")
	private String client_secret;  //"orhonedu对应学校客户秘钥	" 

	@Column(name = "orhonedu_base")
	private String orhonedu_base;  //"orhonedu地址" 

	@Column(name = "deleted_at")
	private Date deleted_at;

	@Column(name = "school_name")
	private String school_name;  

	@Column(name = "introduction")
	private String introduction;

	@Column(name = "icon")
	private String icon;

	@Column(name = "city_id")
	private Integer city_id;

	@Column(name = "district_id")
	private Integer district_id;

	@Column(name = "header_img")
	private String header_img;

	@Column(name = "main_color")
	private String main_color;

	@Column(name = "mark")
	private String mark;

	@Column(name = "cloud_status")
	private Integer cloud_status;

	@Column(name = "lng")
	private String lng;

	@Column(name = "lat")
	private String lat;

	@Column(name = "address")
	private String address;

	@Column(name = "province_id")
	private Integer province_id;

	@OneToOne( cascade = CascadeType.ALL , fetch = FetchType.LAZY)
	@Where(clause = "ISNULL(deleted_at)")
	@JoinColumn(name = "parent_id")
	@NotFound(action=NotFoundAction.IGNORE)
	private Schools schools;   

	//学校模块
	@ManyToMany( cascade = CascadeType.ALL , fetch = FetchType.LAZY)

	@JoinTable(name = "systemctl_modules_school_relations",
	joinColumns = { @JoinColumn(name = "school_id")}, 
	inverseJoinColumns = { @JoinColumn(name = "module_id")})
	@Where(clause = "ISNULL(deleted_at)")
	@NotFound(action=NotFoundAction.IGNORE)
	List<Modules> modules;

	//学校的全部用户
	@OneToMany( cascade = CascadeType.ALL , fetch = FetchType.LAZY)
	@Where(clause = "ISNULL(deleted_at)")
	@JoinColumn(name = "school_id")
	@NotFound(action=NotFoundAction.IGNORE)
	List<Users> users;

	//学校的全部学生
	@OneToMany( cascade = CascadeType.ALL , fetch = FetchType.LAZY)
	@Where(clause = "ISNULL(deleted_at)")
	@JoinColumn(name = "school_id")
	@NotFound(action=NotFoundAction.IGNORE)
	List<SInformation> students;

	//学校的全部老师
	@OneToMany( cascade = CascadeType.ALL , fetch = FetchType.LAZY)
	@Where(clause = "ISNULL(deleted_at)")
	@JoinColumn(name = "school_id")
	@NotFound(action=NotFoundAction.IGNORE)
	List<TInformation> teachers;

	//学校配置
	@OneToMany( cascade = CascadeType.ALL , fetch = FetchType.LAZY)
	@Where(clause = "ISNULL(deleted_at)")
	@JoinColumn(name = "school_id")
	@NotFound(action=NotFoundAction.IGNORE)
	private List<Schoolsettings> settings;


	@Override
	public String toString() {
		return "Schools{" +
				"id=" + id +
				'}';
	}
}
